﻿using System;
using System.Data;
using System.Web.UI;
using Fjaspx.Common;


namespace Fjaspx.UI.Web
{
    public partial class class_edit : AdminPage
	{ 
        #region ClassKind属性
        protected int ClassKind
        {
            get
            {
                return (int)ViewState["ClassKind"];
            }
            set
            {
                ViewState["ClassKind"] = value;
            }
        }
        #endregion
		Fjaspx.Sys.Model.ROYcms_class model = new Fjaspx.Sys.Model.ROYcms_class();
        Fjaspx.Sys.Bll.ROYcms_class BLL = new Fjaspx.Sys.Bll.ROYcms_class();
        Fjaspx.Sys.Model.ROYcmsConfig config = Fjaspx.Config.ROYcmsConfig.Get_Config();
		protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                SystemCms.AdminSesion();
                this.ClassKind = Convert.ToInt32(Request.QueryString["ClassKind"] == null ? "10" : Request.QueryString["ClassKind"]);
                DateBind();
            }
		}

        void DateBind() 
        {
              model = BLL.GetModel(Request["ClassId"]);
              //模板地址
             txtClassName.Text = model.ClassName.Trim();
             if (model.FilePath != "")
             {
                 txtFilePath.Text = model.FilePath.Trim();
             }
             else 
             {
                 txtFilePath.Text = "{cmspath}/" + Guid.NewGuid().ToString() + "/";
             }

             txtColumnsType.SelectedValue = model.ColumnsType.ToString();
             if (model.TemplateIndex != "")
             {
                 txtTemplateIndex.Text = model.TemplateIndex.Trim();
             }
             else 
             {
               txtTemplateIndex.Text = config.templet_root +"default/index.html";
             }
             if (model.TemplateList != "")
             {
                 txtTemplateList.Text = model.TemplateList.Trim();
             }
             else
             {
                 txtTemplateList.Text = config.templet_root + "default/list.html";
             }
             if (model.TemplateShow != "") 
             {
                 txtTemplateShow.Text = model.TemplateShow.Trim();
             }
             else
             {
                 txtTemplateShow.Text = config.templet_root + "default/show.html";
             }
             if (model.ListeRules != "")
             {
                 txtListeRules.Text = model.ListeRules.Trim();
             }
             else
             {
                 txtListeRules.Text = "list_{page}" + config.web_forge;
             }
             if (model.ShowRules != "")
             {
                 txtShowRules.Text = model.ShowRules.Trim();
             }
             else
             {
                 txtShowRules.Text = "{yyyy}/{MM}/{dd}/{id}" + config.web_forge;
             }
             if (model.DefaultFile != "")
             {
                 txtDefaultFile.Text = model.DefaultFile.Trim();
             }
             else
             {
                 txtDefaultFile.Text = "index" + config.web_forge;
             }
             Fck.Value = model.contents;
        
        }
        #region 编辑保存栏目信息
        protected void btnEdit_Click(object sender, EventArgs e)
        {
            int Id = Convert.ToInt32(Request["Id"]);
            string ClassId = Request["ClassId"];   
            string ClassName = this.txtClassName.Text.Trim();
            string ClassList = "";                                            //栏目包含列表
            string ClassPre = Request["ClassPre"];              //上一级目录
            int ClassTj = 1;                                                  //栏目深度
            int ClassKind = Convert.ToInt32(Request["ClassKind"]);    

            if (ClassPre == "0")
            {
                ClassList = ClassId + ",";
                ClassTj = 1;
            }
            else
            {
                DataSet ds = new Fjaspx.Sys.Bll.ROYcms_class().GetClassListByClassId(ClassPre);

                if (ds.Tables[0].Rows.Count > 0)
                {
                    DataRow dr = ds.Tables[0].Rows[0];
                    ClassList = dr["ClassList"].ToString().Trim() + ClassId + ",";
                    ClassTj = Convert.ToInt32(dr["ClassTj"]) + 1;
                }
            }
            model.Id = Id;
            model.ClassId = ClassId;
            model.ClassName = ClassName;
            model.ClassList = ClassList;
            model.ClassPre = ClassPre;
            model.ClassTj = ClassTj;

            model.ClassOrder = 0;
            model.ClassKind = ClassKind;

            model.ListType = 0;
            model.GoType = 0;
            model.DefaultFile = txtDefaultFile.Text;
            model.FilePath = txtFilePath.Text;
            model.ColumnsType =Convert.ToInt32(txtColumnsType.SelectedValue);
            model.WebsiteUrl = txtWebsiteUrl.Text;
            model.TemplateIndex = txtTemplateIndex.Text;
            model.TemplateList = txtTemplateList.Text;
            model.TemplateShow = txtTemplateShow.Text;
            model.ListeRules = txtListeRules.Text;
            model.ShowRules = txtShowRules.Text;
            model.keyword = txtkeyword.Text;
            model.Description = txtDescription.Text; ;
            model.contents = Fck.Value;


            if (new Fjaspx.Sys.Bll.ROYcms_class().ClassSave(model))
            {
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "ajaxjs", "alert('栏目编辑成功！')", true);
            }
            else
            {
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "ajaxjs", "alert('栏目保存操作失败！')", true);
            }
            //this.txtClassName.Text = "";
           
        }
        #endregion

	}
}
